#include "DemoSceneScreen.hpp"
#include "../SceneManager.hpp"
#include "../Entities/SphereEntity.hpp"
#include "../Camera/CameraObject.hpp"
#include "../Camera/CameraManager.hpp"

#include "../ResourceManagers/textfile.h"

#include <assert.h>

#include "../HDRDemoConstants.hpp"



DemoSceneScreen::DemoSceneScreen() :
m_camera1( NULL ),
m_camera2( NULL )
{
	//! Set type of screen.
	m_type = SCREEN_SCENE;
		
	//! Create and add two new cameras.
	//float fov = 45.0f; float near = 1.0f; float far = 1000.0f;
 
	m_camera1 = new CameraObject( MVector3D( 0.0f, 0.0f, 0.0f ), MVector3D( 0.0f, 1.0f, 0.0f ),
							MVector3D( 1.0f, 0.0f, 0.0f ), MVector3D( 15.0f, 10.0f, 20.0f ), 
							45.0, 1.0, 100.0 );
							//fov, near, far );

	m_camera2 = new CameraObject( MVector3D( 0.0f, 0.0f, 0.0f ), MVector3D( 0.0f, 1.0f, 0.0f ),
							MVector3D( 1.0f, 0.0f, 0.0f ), MVector3D( -15.0f, 10.0f, 20.0f ), 
							45.0, 1.0, 100.0 );
							//fov, near, far );

	CameraManager::GetInstance()->RegisterCamera( m_camera1 );
	CameraManager::GetInstance()->RegisterCamera( m_camera2 );

	//! Set m_camera2 as active camera (scene will be rendered from its point of view).
	m_camera2->ActivateCamera();

	//! Initialize entities for this scene.
	InitializeEntities();

	glClearColor(0.4f, 0.4f, 0.4f, 0.0f);
}

DemoSceneScreen::~DemoSceneScreen()
{
	//! Unregister cameras so they can be destroyed.
	CameraManager::GetInstance()->UnregisterAllCameras();
}

bool DemoSceneScreen::InitializeEntities()
{
	SphereEntity* sphere1 = new SphereEntity;
	sphere1->SetPosition( MVector3D( 0.0f, 0.0f, 0.0f ) );
	sphere1->SetDiffuseMaterial( MVector3D( 0.5f, 0.5f, 0.5f ) );
	sphere1->SetSpecularMaterial( MVector3D( 1.0f, 1.0f, 1.0f ) );
	sphere1->SetShininess( 20.0f );
	SceneManager::GetInstance()->RegisterEntity( sphere1 );

	SphereEntity* sphere2 = new SphereEntity;
	sphere2->SetPosition( MVector3D( -3.0f, 0.0f, -5.0f ) );
	sphere2->SetScale( 2.0f );
	sphere2->SetDiffuseMaterial( MVector3D( 0.9f, 0.1f, 0.1f ) );
	sphere2->SetSpecularMaterial( MVector3D( 1.0f, 1.0f, 1.0f ) );
	sphere2->SetShininess( 5.0f );
	SceneManager::GetInstance()->RegisterEntity( sphere2 );


	SphereEntity* sphere3 = new SphereEntity;
	sphere3->SetPosition( MVector3D( 9.0f, 0.0f, -3.0f ) );
	sphere3->SetScale( 1.5f );
	sphere3->SetDiffuseMaterial( MVector3D( 0.1f, 0.1f, 0.7f ) );
	sphere3->SetSpecularMaterial( MVector3D( 1.0f, 1.0f, 1.0f ) );
	sphere3->SetShininess( 5.0f );
	SceneManager::GetInstance()->RegisterEntity( sphere3 );


	SphereEntity* sphere4 = new SphereEntity;
	sphere4->SetPosition( MVector3D( 4.0f, 0.0f, 6.0f ) );
	sphere4->SetDiffuseMaterial( MVector3D( 0.6f, 0.6f, 0.1f ) );
	sphere4->SetSpecularMaterial( MVector3D( 1.0f, 1.0f, 1.0f ) );
	sphere4->SetShininess( 10.0f );
	SceneManager::GetInstance()->RegisterEntity( sphere4 );

	return true;
}

bool DemoSceneScreen::CleanUpEntities()
{
	SceneManager::GetInstance()->UnregisterAllEntities();

	return true;
}